<% title_tag t("users.register_user") %>

<% auth_session = session[:omniauth] || {}
   auth_info = auth_session["info"] || {}
   if auth_info
     resource.omniauth_provider = auth_session["provider"]
     resource.omniauth_uid = auth_session["uid"]
   
     resource.email = auth_info["email"] if resource.email.blank?
     resource.name = auth_info["name"] if resource.name.blank?
     if resource.login.blank?
       resource.login = auth_info["login"] || auth_info["name"]
     end
   end %>


<div class="row">
  <div class="col"></div>
  <div class="col-lg-6">
    <% if auth_info.present? %>
    <div class="card card-lg">
      <div class="card-body">
        <p class="lead">如果你<strong>已经有账号</strong>，你可以直接通过 <%= link_to "登录", new_session_path(resource_name) %> 来绑定<strong><%= Homeland::Utils.omniauth_name(resource.omniauth_provider) %></strong>账号。</p>
      </div>
      </div>
    <% end %>
    <div class="card card-lg">
      <div class="card-body">
        <div class="card-title">
          <%= t("users.register_user") %>
        </div>
        <% if auth_info.present? %>
        <div class="alert">
          <p class="lead">如果你<strong>没有注册过社区账号</strong>，您必须填写以下表单才能完成绑定 <strong><%= Homeland::Utils.omniauth_name(resource.omniauth_provider) %></strong> 的登录方式。</p>
        </div>
        <% end %>

        <%= form_for resource, as: resource_name, url: registration_path(resource_name) do |f| %>
          <% if auth_info.present? %>
            <%= f.hidden_field :omniauth_provider %>
            <%= f.hidden_field :omniauth_uid %>
          <% end %>

          <%= render "shared/error_messages", target: resource %>

          <%= form_group(f, :login) do %>
            <%= f.text_field :login, class: "form-control form-control-lg", placeholder: t("users.login"), hint: t("users.suggest_using_twitter_id") %>
          <% end %>

          <%= form_group(f, :name) do %>
            <%= f.text_field :name, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.name") %>
          <% end %>

          <%= form_group(f, :email) do %>
            <%= f.text_field :email, type: :email, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.email") %>
          <% end %>

          <div class="form-group">
            <div class="custom-control custom-checkbox custom-checkbox-lg">
              <%= f.check_box :email_public, checked: true, class: "custom-control-input" %>
              <label for="user_email_public"  class="custom-control-label"><%= t("activerecord.attributes.user.email_public") %></label>
            </div>
          </div>

          <%= form_group(f, :password) do %>
            <%= f.password_field :password, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.password") %>
          <% end %>

          <%= form_group(f, :password_confirmation) do %>
            <%= f.password_field :password_confirmation, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.password_confirmation") %>
          <% end %>

<!--
          <%= form_group(f, :invite_code) do %>
            <%= f.text_field :invite_code, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.invite_code") %>
          <% end %>
-->



                    
          <div data-controller='phonecheck'>

          <%= form_group(f, :phone_number) do %>
            <%= f.text_field :phone_number, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.phone_number"), "data-phonecheck-target" => "phoneNumber" %>
          <% end %>

          <%= form_group(f, :phone_captcha, label: false) do %>
            <div class="input-group input-group-lg">
              <div class='tw-w-full tw-flex tw-justify-between'>
                <div class='tw-flex '>
                  <%= rucaptcha_input_tag(class: "form-control tw-w-48 form-control-lg", placeholder: t("common.captcha"), "data-phonecheck-target" => "captcha") %>
                  <div class="input-group-append input-group-captcha">
                    <span class="input-group-text" style="padding: 3px 4px; background: #fff;">
                      <a class="rucaptcha-image-box" href="#"><%= rucaptcha_image_tag %></a>
                    </span>
                  </div>
                </div>
                
                <div>
                  <a data-action='click->phonecheck#sendMsg' data-phonecheck-target='sendButton'  class='btn btn-secondary btn-lg'>
                    发送短信验证
                  </a>
                </div>
              </div>
            </div>
          <% end %>
          </div>

          <%= form_group(f, :phone_code, label: false) do %>
            <%= f.text_field :phone_code, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.phone_code") %>
          <% end %>

          

          <div class="form-actions">

            <%= f.submit t("users.submit_new_user"), class: "btn btn-lg btn-primary", "data-disable-with" => t("common.submitting") %>
          </div>
        <% end %>
      </div>
    </div>
  </div>
  <div class="col"></div>
</div>
